<?php
namespace Admin\Controller;
use Think\Controller;

class ConfigController extends Controller{
	public function index(){
		$cfg=M('config');
		$Page= new\Think\Page($count,5);
		$show=$Page->show();
		$list=$cfg->select();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->display();
	}
	public function insert(){
		$cfg = D("config");
		$upload = new\Think\Upload();
		$upload->maxSize = 3145728;
		$upload->exts = array('jpg','gif','png','jpeg');
		$upload->rootPath = './Public'; 
		$upload->savePath = "/upload/config/image/";
		$upload->subName = "";
		$info = $upload->upload();
	 	$_POST['picture']=$info['picture']['savename'];
	 	if($cfg->create()){
	 		$result=$cfg->add();
	 			if($result){
	 					$this->success('数据添加成功',U('config/index'));
	 						}else{$this->error('数据添加失败',U('config/index'));}
	 					}else{
	 		$this->error($cfg->getError());}
	}
	public function del(){
		$cfg = M("config");
		$result=$cfg->where(array('id'=>array('eq',$_GET['id'])))->delete();
			if($result){
				$this->success("删除成功",U('Config/index'));
			}else{
				$this->error("删除失败");
			}
	}
	public function edit(){
		$cfg = M('config');
		$vo = $cfg->where(array('id'=>array('eq',$_GET['id'])))->find();
		$this->assign('vo',$vo);
		$this->display();
	}
	public function save(){
		$cfg = M('config');
		$upload = new\Think\Upload();
		$upload->maxSize=3145728;
		$upload->exts = array('jpg','gif','png','jpeg');
		$upload->rootPath = './Public';
		$upload->savePath = '/upload/config/image/';
		$upload->subName = "";
		$info = $upload->upload();
		$_POST['picture']=$info['picture']['savename'];
		if($cfg->create()){
			$result = $cfg->save();
			if($result){
				$this->success('操作成功',U('config/index'));
			}else{
				$this->error('写入错误');
			}
		}else{
			$this->error($cfg->getError());
		}

	}
}